//
//  TestEngine.h
//  CollectionTest
//
//  Created by Dusan Vujosevic on 2013-10-25.
//  Copyright (c) 2013 Suavetech. All rights reserved.
//

#ifndef __CollectionTest__TestEngine__
#define __CollectionTest__TestEngine__

#include <unistd.h>

#include "CollectionBase.h"
#include "MemUsed.h"

typedef unsigned char bufType;

class CodeDataUsage
{
public:
	void SetBaseline()
	{
		_baselineDataUsage = STGetMemUsed();
	}
	
	uint64_t DataUsage()
	{
		return STGetMemUsed() - _baselineDataUsage;
	}
	
private:
	uint64_t _baselineDataUsage;
};

class TestEngine
{
public:
	TestEngine();
	virtual ~TestEngine();
	
	bool init();
	
	size_t elemCount() const { return _loadElementsCount; }
	
	bool runTest(CollectionBase* collection);
	
private:
	inline size_t testLoadBytesSize() const { return _testLoadElementsCount * sizeof(elemType); }
	inline size_t testSearchBytesSize() const { return _testSearchElementsCount * sizeof(elemType); }
	inline size_t loadBytesSize() const { return _loadElementsCount * sizeof(elemType); }
	inline size_t searchBytesSize() const { return _searchElementsCount * sizeof(elemType); }
	bool fillBytes(int fd, bufType* buf, size_t bufSize);
	void clearBuffers();
	bool runFunctionalTest(CollectionBase* collection);
	bool doRunTest(CollectionBase* collection);

	size_t _testLoadElementsCount;
	size_t _testSearchElementsCount;
	bufType* _loadTestBytes;
	bufType* _searchTestBytes;

	size_t _loadElementsCount;
	size_t _searchElementsCount;
	bufType* _loadBytes;
	bufType* _searchBytes;
	CodeDataUsage _dataUsage;
};

#endif /* defined(__CollectionTest__TestEngine__) */
